package cn.tedu.file;

import java.io.*;

/**本类用于字节输出流*/
public class TestOut {
    public static void main(String[] args) {
//        method1();//用于测试普通字节输出流
        method2();//用于测试高效字节输出流
    }

    private static void method2() {
            BufferedOutputStream out = null;
            try{
//                out = new BufferedOutputStream(new FileOutputStream(new File("C:\\kaifa\\ready\\1.txt")));//覆盖输出
//                out = new BufferedOutputStream(new FileOutputStream("C:\\kaifa\\ready\\1.txt"));
//                out = new BufferedOutputStream(new FileOutputStream(new File("C:\\kaifa\\ready\\1.txt"),true));//追加输出
                out = new BufferedOutputStream(new FileOutputStream("C:\\kaifa\\ready\\1.txt",true));
                out.write(100);
                out.write(100);
                out.write(100);
                out.write(100);
            }catch(Exception e){
                e.printStackTrace();
            }finally {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    }

    private static void method1() {
        FileOutputStream out = null;
        try {
//            out = new FileOutputStream(new File("C:\\kaifa\\ready\\1.txt"));//覆盖输出
//            out = new FileOutputStream("C:\\kaifa\\ready\\1.txt");
//            out = new FileOutputStream(new File("C:\\kaifa\\ready\\1.txt"),true);//追加输出
            out = new FileOutputStream("C:\\kaifa\\ready\\1.txt",true);
            out.write(97);//ASCII码表中a write参数列表是int
            out.write(98);//ASCII码表中b
            out.write(99);//ASCII码表中c

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
